#ifndef _BARTER_SERVER_DBMANAGER_H_
#define _BARTER_SERVER_DBMANAGER_H_

/*
Includes:
	Handle.h: Handle<T>
		Smart handling of pointers to data
	IDatabase.h: IDatabase
		Abstraction of Database system
	Module.h: Module
		Cross-platform smart handling of module instances
*/
#include "Handle.h"
#include "IDatabase.h"
#include "Module.h"

class DBInstance
{
private:
	IDatabase* dbHandle;
	Module* moduleHandle;
public:
	DBInstance(Module*);
	~DBInstance();
	IDatabase* operator->();
	IDatabase* GetDBHandle();
	IDatabase& operator*();
	IDatabase& GetDBReference();
};

class DBManager
{
private:
	std::string currentModule;
	std::vector<Handle<DBInstance> > DBInstances;
	DBManager(); /* Utilize Singleton design pattern */
	DBManager(const DBManager&);
	DBManager& operator=(const DBManager&);
public:
	~DBManager();
	void Init(); // Called when the config file is done loading
	Handle<DBInstance> NewDatabaseInstance();
	static DBManager& Instance();
};

#define dbMan DBManager::Instance()

#endif // _BARTER_SERVER_DBMANAGER_H_
